extends "res://ui/msgBase/msgBase.gd"

var infoCha:Chara = null
var bfDir = config.bfDir
var gSys = globalData.infoDs["g_azurlaneSys"]
var tooltips = globalData.infoDs["g_azurlaneTooltips"]
var utils = globalData.infoDs["g_azurlaneUtils"]
func _on_Button_pressed():
	if infoCha != null:
		queue_free()
		var msg = sys.newMsg("evolutionMsg")
		msg.popup()
		msg.init(infoCha)

func init(cha, s = ""):
	popup()
	infoCha = cha
	var s2 = infoCha.getSkillStrs()
	for i in bfDir.keys():
		s = s.replace(i, "[color=#ffff55][url={id}]{ids}[/url][/color]".format({id = i, ids = tr(i)}))
		s2 = s2.replace(i, "[color=#ffff55][url={id}]{ids}[/url][/color]".format({id = i, ids = tr(i)}))

	$Button.disabled = not infoCha.sureEvo
	if is_instance_valid(sys.main) and sys.main.isAiStart:$Button.disabled = true
	# if infoCha.mainId != "":
	# 	s = s.replace(infoCha.mainName, "[color=#ffff55][url={id}]{ids}[/url][/color]".format({id = "$main", ids = infoCha.mainName}))
	# if infoCha.torpId != "":
	# 	s = s.replace(infoCha.torpName, "[color=#ffff55][url={id}]{ids}[/url][/color]".format({id = "$torp", ids = infoCha.torpName}))

	var lb = utils.createRichTextLabel(s2, self, Vector2(1500, 281), Vector2(48, 278))
	lb.connect("meta_clicked", self, "_on_txt_meta_clicked")

	$txt.bbcode_text = s

func _on_txt_meta_clicked(meta):
	if meta.find("$main") > -1:
		var msg = sys.newMsg("itemInfoMsg")
		utils.changeScript(msg, gSys.itemInfoMsgScript)
		var item = sys.newItem(infoCha.mainId)
		item.delayInit()
		msg.init(item, tooltips.getInfo(item))
	elif meta.find("$torp") > -1:
		var msg = sys.newMsg("itemInfoMsg")
		utils.changeScript(msg, gSys.itemInfoMsgScript)
		var item = sys.newItem(infoCha.torpId)
		item.delayInit()
		msg.init(item, tooltips.getInfo(item))
	else:
		sys.newBaseMsg(meta, bfDir[meta])
	

	
